//
//  LoginView.m
//  SportSocial
//
//  Created by yull on 14/11/25.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "LoginView.h"
#import "UIView+Frame.h"
#import "LoginCell.h"

@implementation LoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.loginTable = [[UITableView alloc] initWithFrame:self.bounds];
        self.loginTable.delegate = self;
        self.loginTable.dataSource = self;
        self.loginTable.backgroundColor = [UIColor clearColor];
        self.loginTable.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        self.loginTable.separatorInset = UIEdgeInsetsMake(0, 15, 0, 0);
        [self addSubview:self.loginTable];
        
        self.loginTable.tableFooterView = [[UIView alloc] init];
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"LoginCell";
    LoginCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell = [[LoginCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.textColor = [UIColor whiteColor];  
    }
    
    if (indexPath.row == 0) {
        [cell drawCellWithText:@"登录" image:nil];
    }else if (indexPath.row == 1) {
        [cell drawCellWithText:@"注册" image:nil];
    }else if (indexPath.row == 2) {
        [cell drawCellWithText:@"QQ账号注册" image:[UIImage imageNamed:@"qq_login_icon"]];
    }else if (indexPath.row == 3) {
        [cell drawCellWithText:@"微博账号注册" image:[UIImage imageNamed:@"sina_login_icon"]];
    }else {
        [cell drawCellWithText:@"微信账号注册" image:[UIImage imageNamed:@"weixin_login_icon"]];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 && [self.delegate respondsToSelector:@selector(onNormalLogin)]) {
        [self.delegate onNormalLogin];
    }else if (indexPath.row == 1 && [self.delegate respondsToSelector:@selector(onRegister)]) {
        [self.delegate onRegister];
    }else if (indexPath.row == 2 && [self.delegate respondsToSelector:@selector(onQQLogin)]) {
        [self.delegate onQQLogin];
    }else if (indexPath.row == 3 && [self.delegate respondsToSelector:@selector(onSinaWeiboLogin)]) {
        [self.delegate onSinaWeiboLogin];
    } else if (indexPath.row == 4 && [self.delegate respondsToSelector:@selector(onWeixinLogin)]) {
        [self.delegate onWeixinLogin];
    }
}
@end
